package output_handler;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * Class used to write the output file according to given results
 */
public class OutputMngr {

	private PrintWriter writer; // use to write to results file
	private int lineCtr; // counts lines

	/**
	 * Constructor- creates a new object to manage the output file
	 * and a new output file with given name 
	 * @param outputFileName name of output file
	 * @throws IOException if had problems opening file
	 */
	public OutputMngr(String outputFileName) throws IOException {
		
		// open output file
		writer = new PrintWriter(new BufferedWriter(new FileWriter(new File(
				outputFileName))));
		
		// initialize line counter
		lineCtr = 1;
	}
	
	/**
	 * Writes given string to the output file as a new line 
	 * @param newLine new line to write
	 */
	public void addLine(String newLine) {
		writer.println("Output" + lineCtr + ": " + newLine);
		++lineCtr;
	}
	
	/**
	 * Closes output file
	 */
	public void closeOutput() {
		writer.close();
	}
}
